package org.project.product.android.pfe_fanta;

import org.project.product.android.pfe.fanta.R;
import org.project.product.android.pfe.fanta.adapter.DataManagerFacade;
import org.project.product.android.pfe.fanta.domain.Product;
import org.project.product.android.pfe.fanta.util.Utils;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class SearchByProductName extends Activity {

	private EditText eanInput;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.search_productname);
		eanInput = (EditText) findViewById(R.id.entryEAN);

	}

	public void searchProductByName(View v) {
		if (Utils.checkEditText(this, eanInput)) {
			String name = eanInput.getText().toString();
			Product product = DataManagerFacade.getInstance(this)
			        .searchProductByName(name);
			if (product == null) {
				Toast.makeText(this, "No product matching this name",
				        Toast.LENGTH_SHORT).show();
			} else {
				Utils.lancerActivity(this, ProductViewActivity.class, product);
			}
		}

	}

}
